const app = getApp()
import $service from '../../service'
let page = 1
let loading = true

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    height: {
      type: String,
      value: '100vh'
    },
    logId: {
      type: String,
      value: ''
    },
    idCard: {
      type: String,
      value: ''
    }
  },
  lifetimes: {
    ready() {
      page = 1
      this.getUserRecordsInfo()
      this.getInquiryLogByUserIdList()
    }
  },
  data: {
    hospitalName: wx.getStorageSync('hospitalName'),
    recordsInfo: {},
    wzlslist: [],
    total: 1,
    index: 1
  },

  methods: {
    getUserRecordsInfo() {
      app.http.getUserRecordsInfo({id: this.properties.logId}).then(res => {
        // 0 未婚 1 已婚 2 离婚  3 丧偶
        let marriedList =  ['未婚', '已婚', '离婚', '丧偶']
        res.data.married = marriedList[res.data.isMarried]
        this.setData({
          recordsInfo: res.data
        })
      }).catch(err => {
        $service.showToast(err.msg)
      })
    },
    getInquiryLogByUserIdList() {
      let params = {
        "current": page,
        "identityCard": this.properties.idCard,
        // "identityCard": '441900199310122787',
        "size": 10
      }
      app.http.getInquiryLogByUserIdList(params).then(res => {
          if (res.data && res.data.total > this.data.wzlslist.length) {
            let list = [...this.data.wzlslist, ...res.data.list]
            this.setData({
              wzlslist: list,
              total: res.data.total + 1
            })
          } else {
            loading = false
          }
      }).catch(err => {
          $service.showToast(err.msg)
      })
    },
    swiperChange(e) {
      this.setData({
        index: e.detail.current + 1
      })
      if (this.data.index == this.data.wzlslist.length - 3 && loading) {
        page ++ 
        this.getInquiryLogByUserIdList()
      }
    },
    viewImg(e) {
      wx.previewImage({
        urls: [e.currentTarget.dataset.img],
      })
    }
  }
})
